package com.tencent.iov.cowin.befsale.clue.controller.mask;

import com.tencent.iov.cowin.befsale.clue.component.MaskComponent;
import com.software.boot.common.entity.Response;
import com.tencent.iov.cowin.befsale.clue.controller.mask.vo.request.TopicRequest;
import com.tencent.iov.cowin.befsale.clue.service.clue.KafkaService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author: Caychen
 * @Date: 2022/2/14 10:25
 * @Description:
 */
@RestController
@RequestMapping(value = "/api/v1/mask")
@Api(tags = "加密脱敏示例")
public class MaskController {

    @Autowired
    private MaskComponent maskComponent;

    @Autowired
    private KafkaService producer;


    /**
     * 加密
     *
     * @param content
     * @return
     */
    @PostMapping("/encryptAES128")
    public Response<String> encryptAES128(String content) {
        String encryptAES128 = maskComponent.encryptAES128(content);
        return Response.success(encryptAES128);
    }

    /**
     * 解密
     *
     * @param content
     * @return
     */
    @PostMapping("/decryptAES128")
    public Response<String> decryptAES128(String content) {
        String decryptAES128 = maskComponent.decryptAES128(content);
        return Response.success(decryptAES128);
    }

    /**
     * 手机号解密不脱敏
     *
     * @param phone
     * @return
     */
    @PostMapping("/mobileDeCryptWithDesensitize")
    public Response<String> mobileDeCryptWithDesensitize(String phone) {
        return Response.success(maskComponent.mobileDeCryptWithDesensitize(phone));
    }

    /**
     * 手机号解密且脱敏
     *
     * @param phone
     * @return
     */
    @PostMapping("/mobileDeCryptWithoutDesensitize")
    public Response<String> mobileDeCryptWithoutDesensitize(String phone) {
        return Response.success(maskComponent.mobileDeCryptWithoutDesensitize(phone));
    }

    /**
     * 身份证解密且脱敏
     *
     * @param idCard
     * @return
     */
    @PostMapping("/idCardDeCryptWithDesensitize")
    public Response<String> idCardDeCryptWithDesensitize(String idCard) {
        return Response.success(maskComponent.idCardDeCryptWithDesensitize(idCard));
    }

    /**
     * 身份证解密不脱敏
     *
     * @param idCard
     * @return
     */
    @PostMapping("/idCardDeCryptWithoutDesensitize")
    public Response<String> idCardDeCryptWithoutDesensitize(String idCard) {
        return Response.success(maskComponent.idCardDeCryptWithoutDesensitize(idCard));
    }

    @PostMapping("/sendTopic")
    public void sendTopic(@RequestBody TopicRequest request){
        producer.send(request.getTopicName(), request.getValue());
    }

}